package com.zhuoyian.analysis;

import java.util.HashMap;

import com.zhuoyian.analysis.common.AnalysisConsts;
import com.zhuoyian.analysis.util.DateUtil;
import com.zhuoyian.analysis.util.EncodeUtil;

public class AnalysisBuilder {

	private HashMap<String, String> hm;

	private AnalysisBuilder() {
		super();
		hm = new HashMap<String, String>();
	}

	/**
	 * 创建
	 * @return
	 */
	public static AnalysisBuilder create() {
		return new AnalysisBuilder();
	}

	/**
	 * apkId
	 * 
	 * @param apkId
	 * @return
	 */
	public AnalysisBuilder putApkId(String apkId) {
		if (apkId == null) {
			apkId = "";
		}
		hm.put(AnalysisConsts.DOWN_APKID, apkId);
		return this;
	}

	/**
	 * apkName
	 * 
	 * @param apkName
	 * @return
	 */
	public AnalysisBuilder putApkName(String apkName) {
		if (apkName == null) {
			apkName = "";
		}
		hm.put(AnalysisConsts.DOWN_APKNAME, EncodeUtil.encodeUTF8(apkName));
		return this;
	}

	/**
	 * apkUrl
	 * 
	 * @param apkUrl
	 * @return
	 */
	public AnalysisBuilder putApkUrl(String apkUrl) {
		if (apkUrl == null) {
			apkUrl = "";
		}
		hm.put(AnalysisConsts.DOWN_APKURL, apkUrl);
		return this;
	}

	/**
	 * 打开方式
	 * 
	 * @param open
	 * @return
	 */
	public AnalysisBuilder putOpen(OpenManner open) {
		if (open == null) {
			open = OpenManner.DEFAULT;
		}
		hm.put(AnalysisConsts.OPEN, "" + open.getValue());
		return this;
	}

	/**
	 * 状态
	 * 
	 * @param state
	 * @return
	 */
	public AnalysisBuilder putState(DownLoadState state) {
		if (state == null) {
			state = DownLoadState.CLICK;
		}

		hm.put(AnalysisConsts.STATE, "" + state.getValue());
		return this;
	}

	/**
	 * 退出时间
	 * 
	 * @return
	 */
	public AnalysisBuilder putExitTime() {
		hm.put(AnalysisConsts.EXIT_TIME, DateUtil.getCurDate());
		return this;
	}

	/**
	 * 进入时间
	 * 
	 * @param time
	 * @return
	 */
	public AnalysisBuilder putComeTime(String time) {
		if (time == null) {
			time = "";
		}
		if (!time.contains("-")) {
			time = DateUtil.getDate(Long.parseLong(time));
		}
		hm.put(AnalysisConsts.COME_TIME, time);
		return this;
	}

	/**
	 * 图片地址
	 * 
	 * @param img
	 * @return
	 */
	public AnalysisBuilder putImg(String img) {
		if (img == null) {
			img = "";
		}
		hm.put(AnalysisConsts.IMG, img);
		return this;
	}

	/**
	 * 图片下载地址
	 * 
	 * @param img
	 * @return
	 */
	public AnalysisBuilder putImgUrl(String imgUrl) {
		if (imgUrl == null) {
			imgUrl = "";
		}
		hm.put(AnalysisConsts.IMG_URL, imgUrl);
		return this;
	}
	public AnalysisBuilder putUrl(String url) {
		if (url == null) {
			url = "";
		}
		hm.put(AnalysisConsts.URL, url);
		return this;
	}

	/**
	 * 是否中断
	 * 
	 * @param isBreak
	 * @return
	 */
	public AnalysisBuilder putIsBreak(IsBreak isBreak) {
		if (isBreak == null) {
			isBreak = IsBreak.NOTSKIP;
		}
		hm.put(AnalysisConsts.IS_BREAK, "" + isBreak.getValue());
		return this;
	}
	
	/**
	 * 点击
	 */
	public AnalysisBuilder putClick(Click click) {
		if (click == null) {
			click = Click.CLICK;
		}
		hm.put(AnalysisConsts.CLICK, "" + click.getValue());
		return this;
	}
	
	/**
	 * 停留时间
	 * @param stayTime
	 * @return
	 */
	public AnalysisBuilder putStayTime(String stayTime) {
		if (stayTime == null) {
			stayTime = "";
		}
		hm.put(AnalysisConsts.STAY_TIME, stayTime);
		return this;
	}

	/**
	 * @return
	 */
	public HashMap<String, String> getData() {
		return hm;
	}

	/**
	 * 状态
	 * @author Administrator
	 *
	 */
	public enum DownLoadState {
		CLICK(0), ENTER(1), FINSH(2);
		private int value;
		private DownLoadState(int value) {
			this.value = value;
		}

		public int getValue() {
			return value;
		}
	};
	
	/**
	 * 点击
	 */
	public enum Click{
		CLICK(1), WAIT(2), FINSH(3);
		private int value;
		private Click(int value) {
			this.value = value;
		}
		
		public int getValue() {
			return value;
		}
	};

	/**
	 * 打开方法
	 * @author Administrator
	 *
	 */
	public enum OpenManner {
		NOTIFY(0), DEFAULT(1), AUTO(2);

		private int value;
		private OpenManner(int value) {
			this.value = value;
		}

		public int getValue() {
			return value;
		}
	};

	/**
	 * 是否中断
	 * @author Administrator
	 *
	 */
	public enum IsBreak {
		NOTSKIP(0), SKIP(1);

		private int value;
		private IsBreak(int value) {
			this.value = value;
		}

		public int getValue() {
			return value;
		}
	};
}
